package com.ldc.work_1203.controller;

import com.github.pagehelper.PageInfo;
import com.ldc.work_1203.bean.Company;
import com.ldc.work_1203.bean.Inquire;
import com.ldc.work_1203.bean.Jobinfo;
import com.ldc.work_1203.bean.Student;
import com.ldc.work_1203.service.CompanyService;
import com.ldc.work_1203.service.InquireService;
import com.ldc.work_1203.service.StudentService;
import com.ldc.work_1203.util.PagerUtil;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("/inquire")
public class InquireController {

    @Autowired
    private InquireService inquireService;

    @Autowired
    private CompanyService companyService;

    @Autowired
    private StudentService studentService;

    @RequestMapping("getListInguire")
    public String getListInguire(Model model, String studentName, String companyName, Double miaPay, Double maxPay, Integer currentPage){

        PageInfo<Inquire> listInquire = inquireService.getListInquire(studentName, companyName, miaPay, maxPay, currentPage);

        model.addAttribute("getInquire",listInquire);
        model.addAttribute("companyName",companyName);
        model.addAttribute("studentName",studentName);
        model.addAttribute("miaPay",miaPay);
        model.addAttribute("maxPay",maxPay);

        return "list";
    }

    @RequestMapping("/addSkip")
    public String addSkip(Model model){
        List<Company> listCompany = companyService.getListCompany();

        List<Student> listStudent = studentService.getListStudent();

        model.addAttribute("company",listCompany);
        model.addAttribute("student",listStudent);
        return "add";
    }

    @RequestMapping("/addJobinfo")
    public String addJobinfo(Jobinfo jobinfo){
        inquireService.addInquire(jobinfo);

        return "redirect:/inquire/getListInguire";
    }


    @RequestMapping("/upSkip")
    public String upSkip(Model model,Integer JobinfoId){
        List<Company> listCompany = companyService.getListCompany();

        List<Student> listStudent = studentService.getListStudent();

        Jobinfo jobinfo = inquireService.getJobinfo(JobinfoId);

        model.addAttribute("jobinfo",jobinfo);
        model.addAttribute("company",listCompany);
        model.addAttribute("student",listStudent);
        return "alter";
    }


    @RequestMapping("/upJobinfo")
    public String upJobinfo(Jobinfo jobinfo){
        inquireService.upInquire(jobinfo);

        return "redirect:/inquire/getListInguire";
    }


    @RequestMapping("/delJobinfo")
    public String delJobinfo(Integer jobinfoId){
        inquireService.delInquire(jobinfoId);

        return "redirect:/inquire/getListInguire";
    }

}
